package com.ny.demo525.impl;

import com.ny.demo524.SqlConnection;
import com.ny.entity.Order;
import com.ny.demo525.OrderDao;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class OrderDaoImpl implements OrderDao {
private SqlConnection sqlConncetion=new SqlConnection();
public OrderDaoImpl() throws ClassCastException, SQLException, ClassNotFoundException {
    sqlConncetion.getCon();
}
    @Override
    public int addOrder(Order order) throws SQLException, ClassCastException, ClassNotFoundException {
    String  sql="insert into orders(student_id,product_id,number,total_price) values(?,?,?,?)";
        PreparedStatement  preparedStatement = sqlConncetion.getCon().prepareStatement(sql);
        preparedStatement.setInt(1, order.getStudent_id());
        preparedStatement.setInt(2, order.getProduct_id());
        preparedStatement.setInt(3, order.getNumber());
        preparedStatement.setInt(4, order.getTotal_Price());
        return preparedStatement.executeUpdate();
    }
}
